use shared::NetemProfile;
use js_sys::Date;
use yew::prelude::*;

#[derive(Clone, PartialEq, Properties)]
pub struct PresetButtonProps {
    pub profile: NetemProfile,
    #[prop_or_default]
    pub onclick: Callback<NetemProfile>,
}

#[function_component]
pub fn PresetButton(props: &PresetButtonProps) -> Html {
    let onclick = {
        let profile = NetemProfile {
            name: Date::now().to_string(),
            ..props.profile.clone()
        };
        props.onclick.reform(move |_| profile.clone())
    };
    html! {
        <button class="preset-button" {onclick}>{&props.profile.name}</button>
    }
}
